package com.xsd.awen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xsd.awen.config.App;
import com.xsd.awen.domain.po.ViewProjectPo;
import com.xsd.awen.domain.po.ViewUserPo;
import com.xsd.awen.domain.vo.ViewVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ViewMapper extends BaseMapper<App> {

    @Select("<script> SELECT " +
            " ( select GROUP_CONCAT(u.name) from t_tk_user_task ut,t_tk_user u where ut.user_id = u.id and ut.task_id = t.id  ) yfs " +
            " ,t.name task_name,t.start_time,t.stop_time,t.online_time,t.remarks,t.status,t.cp,t.cs,p.in_manager,p.cname " +
            " FROM t_tk_task t " +
            " inner join t_tk_app a on t.app_id = a.id " +
            " inner join t_tk_project p on t.project_id = p.id " +
            " where 1=1 " +
            "<if test=\"projectId != null and projectId != ''\"> and t.project_id = #{projectId}</if>" +
            "<if test=\"gs != null and gs != ''\"> and t.gs = #{gs}</if>" +
            "<if test=\"status != null \"> and t.status = #{status}</if>" +
            "<if test=\"priority != null \"> and p.priority = #{priority}</if>" +
            " order by p.id </script>"
            )
    List<ViewProjectPo> project(ViewVo vo);

    @Select("<script> SELECT " +
            " u.name userName,t.name taskName,t.status,p.cname projectName,ut.start_time,ut.stop_time,t.cp,t.cs ,ut.remarks,p.in_manager " +
            " FROM " +
            " t_tk_user_task ut " +
            " inner join t_tk_task t on ut.task_id = t.id " +
            " inner join t_tk_user u on ut.user_id = u.id " +
            " inner join t_tk_app a on t.app_id = a.id " +
            " inner join t_tk_project p on t.project_id = p.id " +
            " where 1=1 " +
            "<if test=\"userId != null and userId != ''\"> and ut.user_id = #{userId}</if>" +
            "<if test=\"gs != null and gs != ''\"> and u.gs = #{gs}</if>" +
            "<if test=\"status != null \"> and t.status = #{status}</if>" +
            "<if test=\"priority != null \"> and p.priority = #{priority}</if>" +
            " order by u.id </script>"
    )
    List<ViewUserPo> user(ViewVo vo);

}